package com.kiki.stater;

/**
 * Created by mazeyi on 2020/11/5.
 */
public class ArrayTest {


    //最大子数组之和

    /**
     * 问题：
     * 给定一个整数数组nums,找到一个具有最大和的连接子数组(子数组最少包含一个元素)，返回其最大和
     *
     *
     *
     *
     *

     */
    static int maxSubArray(int[] nums){
        int n = nums.length;
        if(n == 0){
            return 0;
        }

        int dp_0 = nums[0];
        int dp_1 = 0;
        int res = dp_0;

        for(int i = 1; i < n; i++){
            dp_1 = Math.max(nums[i], dp_0 + nums[i]);
            dp_0 = dp_1;
            res = Math.max(res, dp_1);
        }
        return res;
    }

    public static void main(String[] args) {
        int max = 4000;
        //最小值
        int min = 5000;

        int dayInterval = 2;

        int reward = 0;
        if (dayInterval == 1) {
            //第1天礼包金额=随机数（最大金额-最小金额）+最小金额。去掉小数，向下取整
            reward = (int) Math.floor((max - min) * Math.random()) + min;
        } else {
            //第n天礼包金额（第2天及以后礼包金额）=随机数（第n天最大金额-第n天最小金额）+第n天最小金额+第n-1天抽奖结余。抽奖结余<=0时，取0

            //算出前一天结余
            int maxed = 2000;
            int mined = 2500;
            int remain = (int) Math.floor((maxed - mined) * 0.7);
            if (remain < 0) {
                remain = 0;
            }
            reward = (int) Math.floor((max - min) * Math.random()) + min + remain;

            System.out.println(reward);

        }

    }
}